package com.lanou.zakerproject.hotspot;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou.zakerproject.R;
import com.lanou.zakerproject.base.VolleySingleton;
import com.lanou.zakerproject.db.DbTool;
import com.lanou.zakerproject.subscribe.ChannelSearch;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/22.
 */
public class HostspotLikeAdapter extends BaseAdapter {
    private Context context;
    private List<String> data;
    private DbTool dbTool;

    public HostspotLikeAdapter(Context context) {
        this.context = context;
        dbTool = new DbTool(context);
        data = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_gridview_hobby, parent, false);
            myViewHolder = new MyViewHolder(convertView);
            convertView.setTag(myViewHolder);
        } else {
            myViewHolder = (MyViewHolder) convertView.getTag();
        }
        if (data != null) {
            myViewHolder.textView.setText(data.get(position));
        }
        return convertView;
    }


    class MyViewHolder {
        TextView textView;
        ImageView imageView;

        public MyViewHolder(View view) {
            textView = (TextView) view.findViewById(R.id.item_hobby_add);
            imageView = (ImageView) view.findViewById(R.id.item_hobby_img);

        }
    }

    //向Adapter添加数据
    public void update(List<String> data) {
        this.data = data;//更新
        notifyDataSetChanged();
    }

    public void delData(int pos) {
        data.remove(pos);
        notifyDataSetChanged();
    }
}

